import { useLocation, useNavigate } from 'react-router-dom';
export const useQueryParams = () => new URLSearchParams(useLocation().search);
export function useURLQuery() {
    const params = useQueryParams();
    const queryParamsObject = {};
    params.forEach((value, key) => {
        queryParamsObject[key] = value;
    });
    const navigate = useNavigate();
    const location = useLocation();
    return {
        query: queryParamsObject,
        replaceQuery(obj) {
            const searchParams = Object.entries({ ...queryParamsObject, ...obj })
                .filter(([_, value]) => value !== undefined)
                .map(([key, value]) => `${key}=${value}`).join('&');
            navigate({ pathname: location.pathname, search: searchParams }, {
                replace: true,
            });
        }
    };
}
